'''
https://leetcode.cn/problems/find-the-town-judge/?envType=study-plan-v2&envId=graph-theory
'''
from typing import List


class Solution:
    def findJudge(self, n: int, trust: List[List[int]]) -> int:
        indegree = [0] * (n + 1)
        outdegree = [0] * (n + 1)
        for u, v in trust:
            indegree[v] += 1
            outdegree[u] += 1
        for i in range(1, n + 1):
            if indegree[i] == n - 1 and 0 == outdegree[i]:
                return i
        return -1